Skip to content

feat: add support for passing metadata to MCP tool calls#423

Open
Uday Shankar (udayshnk) wants to merge 1 commit intolangchain-ai:mainfrom
udayshnk:main
Open

feat: add support for passing metadata to MCP tool calls#423
Uday Shankar (udayshnk) wants to merge 1 commit intolangchain-ai:mainfrom
udayshnk:main

Conversation

@udayshnk

Add metadata support to MCP tool calls

Add metaParams support to MCP tool calls and expose MCP response _meta in
MCPToolArtifact. This allows callers to pass metadata parameters to MCP
tools and access response metadata returned by MCP tool calls alongside
structured_content.

Per the MCP specification (https://modelcontextprotocol.io/specification/2025-06-18/basic/index#general-fields),
_meta is defined as a separate field at the request level. This implementation correctly treats metaParams
as a distinct parameter passed to session.call_tool(meta=...), following the spec's CallToolRequest structure
where _meta is a sibling to 'name' and 'arguments', not nested within arguments. Metadata is passed exclusively
through interceptors, keeping tool arguments clean and protocol-level metadata separate from LLM-facing parameters.

Changes:
- Bump mcp dependency from 1.9.2 to 1.22.0
- Add metaParams field to MCPToolCallRequest for passing metadata to MCP servers
- Add metaParams parameter to tool calls passed as 'meta' to session.call_tool()
- Add _meta field to MCPToolArtifact (with total=False to make both fields optional)
- Update tools and interceptors to support metadata parameters
- Add comprehensive tests for metadata passing and interceptor composition
- Update README documentation with interceptor-based metadata examples
- Ensure clean separation: tool arguments remain pure, metadata handled via interceptors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants